{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "\n",
    "# 独立使用django model（一）\n",
    "# Django Shell\n",
    "# 项目根目录中打开Django Shell : python manage.py shell\n",
    "# import django\n",
    "# django.setup()  # 装载Django\n",
    "# 调用model\n",
    "# django 快速入门 数据操作 https://blog.csdn.net/u011054333/article/details/78767724\n",
    "\n",
    "# 独立使用django model（二）\n",
    "import sys\n",
    "import os\n",
    "import json\n",
    "import requests\n",
    "from django.core.files import File\n",
    "from django.core.files.base import ContentFile\n",
    "\n",
    "\n",
    "# 建立外部脚本链接django项目\n",
    "# 添加环境变量\n",
    "'''\n",
    "print(os.path.abspath('__file__'))\n",
    "print(os.path.dirname(os.path.abspath('__file__')))\n",
    "print(os.path.dirname(os.path.dirname(os.path.abspath('__file__'))))\n",
    "/Users/zhaojinhui/Desktop/webapp/backend/rmis/jupyter_notebook/__file__\n",
    "/Users/zhaojinhui/Desktop/webapp/backend/rmis/jupyter_notebook\n",
    "/Users/zhaojinhui/Desktop/webapp/backend/rmis\n",
    "'''\n",
    "project = os.path.dirname(os.getcwd())  # get current work directory\n",
    "sys.path.append(project)\n",
    "sys.path.append(os.path.join(project,'rmis'))\n",
    "os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')\n",
    "# sys.path.append已设置临时环境变量，可以找到rmis.settings，脚本是外部脚本，只是放在了项目当中而已\n",
    "# 相关数据库配置等在settings.py文件中\n",
    "\n",
    "# 导入并装载django\n",
    "import django\n",
    "django.setup()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(<django.db.models.fields.AutoField: id>,\n",
       " <django.db.models.fields.related.ForeignKey: fk_good>,\n",
       " <django.db.models.fields.CharField: type>,\n",
       " <django.db.models.fields.DateTimeField: created>,\n",
       " <django.db.models.fields.DateTimeField: modified>,\n",
       " <stdimage.models.StdImageField: uri>)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from good.models import GoodMultimedia\n",
    "GoodMultimedia._meta.get_fields(include_parents=True,include_hidden=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False True\n",
      "<class 'good.models.GoodMultimedia'> <class 'good.models.GoodMultimedia'>\n",
      "False True False False <class 'good.models.Good'>\n",
      "<class 'good.models.Good'>\n"
     ]
    }
   ],
   "source": [
    "uri = GoodMultimedia._meta.get_field('uri')\n",
    "fk_good = GoodMultimedia._meta.get_field('fk_good')\n",
    "print(uri.is_relation,fk_good.is_relation)\n",
    "print(uri.model,fk_good.model)\n",
    "print(fk_good.many_to_many,fk_good.many_to_one,fk_good.one_to_many,fk_good.one_to_one,fk_good.related_model)\n",
    "good = fk_good.related_model\n",
    "print(good)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "field good.GoodMultimedia.id\n",
      "is_ralation False\n",
      "None None None None None\n",
      "True False\n",
      "-------------\n",
      "field good.GoodMultimedia.fk_good\n",
      "is_ralation True\n",
      "False True False False <class 'good.models.Good'>\n",
      "False False\n",
      "-------------\n",
      "field good.GoodMultimedia.type\n",
      "is_ralation False\n",
      "None None None None None\n",
      "False False\n",
      "-------------\n",
      "field good.GoodMultimedia.created\n",
      "is_ralation False\n",
      "None None None None None\n",
      "True False\n",
      "-------------\n",
      "field good.GoodMultimedia.modified\n",
      "is_ralation False\n",
      "None None None None None\n",
      "True False\n",
      "-------------\n",
      "field good.GoodMultimedia.uri\n",
      "is_ralation False\n",
      "None None None None None\n",
      "False False\n",
      "-------------\n"
     ]
    }
   ],
   "source": [
    "for field in GoodMultimedia._meta.get_fields(include_parents=True,include_hidden=False):\n",
    "    print('field',field)\n",
    "    print('is_ralation',field.is_relation)\n",
    "    print(field.many_to_many,field.many_to_one,field.one_to_many,field.one_to_one,field.related_model)\n",
    "    print(field.blank, field.null)  # field option\n",
    "    print('-------------')\n",
    "\n",
    "# is_ralation is False\n",
    "# many_to_many is None, many_to_one is None, one_to_many is None, one_to_one is None, related_model is None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "field <ManyToOneRel: admin.logentry>\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name logentry\n",
      "field type <class 'django.db.models.fields.reverse_related.ManyToOneRel'>\n",
      "field <ManyToOneRel: admin.logentry>\n",
      "-------------\n",
      "field <ManyToOneRel: xadmin.bookmark>\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name bookmark\n",
      "field type <class 'django.db.models.fields.reverse_related.ManyToOneRel'>\n",
      "field <ManyToOneRel: xadmin.bookmark>\n",
      "-------------\n",
      "field <ManyToOneRel: xadmin.usersettings>\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name usersettings\n",
      "field type <class 'django.db.models.fields.reverse_related.ManyToOneRel'>\n",
      "field <ManyToOneRel: xadmin.usersettings>\n",
      "-------------\n",
      "field <ManyToOneRel: xadmin.userwidget>\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name userwidget\n",
      "field type <class 'django.db.models.fields.reverse_related.ManyToOneRel'>\n",
      "field <ManyToOneRel: xadmin.userwidget>\n",
      "-------------\n",
      "field <ManyToOneRel: xadmin.log>\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name log\n",
      "field type <class 'django.db.models.fields.reverse_related.ManyToOneRel'>\n",
      "field <ManyToOneRel: xadmin.log>\n",
      "-------------\n",
      "field <ManyToOneRel: guardian.userobjectpermission>\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name userobjectpermission\n",
      "field type <class 'django.db.models.fields.reverse_related.ManyToOneRel'>\n",
      "field <ManyToOneRel: guardian.userobjectpermission>\n",
      "-------------\n",
      "field user.UserProfile.id\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name id\n",
      "field type <class 'django.db.models.fields.AutoField'>\n",
      "field description 整数\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: False\n",
      "-------------\n",
      "field user.UserProfile.password\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name password\n",
      "field type <class 'django.db.models.fields.CharField'>\n",
      "field description 字符串（最长 %(max_length)s 位）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: False null: False\n",
      "-------------\n",
      "field user.UserProfile.last_login\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name last_login\n",
      "field type <class 'django.db.models.fields.DateTimeField'>\n",
      "field description 日期（带时间）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: True\n",
      "-------------\n",
      "field user.UserProfile.is_superuser\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name is_superuser\n",
      "field type <class 'django.db.models.fields.BooleanField'>\n",
      "field description 布尔值（真或假）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: False\n",
      "-------------\n",
      "field user.UserProfile.username\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name username\n",
      "field type <class 'django.db.models.fields.CharField'>\n",
      "field description 字符串（最长 %(max_length)s 位）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: False null: False\n",
      "-------------\n",
      "field user.UserProfile.first_name\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name first_name\n",
      "field type <class 'django.db.models.fields.CharField'>\n",
      "field description 字符串（最长 %(max_length)s 位）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: False\n",
      "-------------\n",
      "field user.UserProfile.last_name\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name last_name\n",
      "field type <class 'django.db.models.fields.CharField'>\n",
      "field description 字符串（最长 %(max_length)s 位）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: False\n",
      "-------------\n",
      "field user.UserProfile.email\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name email\n",
      "field type <class 'django.db.models.fields.EmailField'>\n",
      "field description Email 地址\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: False\n",
      "-------------\n",
      "field user.UserProfile.is_staff\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name is_staff\n",
      "field type <class 'django.db.models.fields.BooleanField'>\n",
      "field description 布尔值（真或假）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: False\n",
      "-------------\n",
      "field user.UserProfile.is_active\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name is_active\n",
      "field type <class 'django.db.models.fields.BooleanField'>\n",
      "field description 布尔值（真或假）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: False\n",
      "-------------\n",
      "field user.UserProfile.date_joined\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name date_joined\n",
      "field type <class 'django.db.models.fields.DateTimeField'>\n",
      "field description 日期（带时间）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: True\n",
      "-------------\n",
      "field user.UserProfile.nickname\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name nickname\n",
      "field type <class 'django.db.models.fields.CharField'>\n",
      "field description 字符串（最长 %(max_length)s 位）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: True\n",
      "-------------\n",
      "field user.UserProfile.birth\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name birth\n",
      "field type <class 'django.db.models.fields.DateField'>\n",
      "field description 日期（无时间）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: True\n",
      "-------------\n",
      "field user.UserProfile.mobile\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name mobile\n",
      "field type <class 'django.db.models.fields.CharField'>\n",
      "field description 字符串（最长 %(max_length)s 位）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: True\n",
      "-------------\n",
      "field user.UserProfile.wechat\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name wechat\n",
      "field type <class 'django.db.models.fields.CharField'>\n",
      "field description 字符串（最长 %(max_length)s 位）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: True\n",
      "-------------\n",
      "field user.UserProfile.gender\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name gender\n",
      "field type <class 'django.db.models.fields.CharField'>\n",
      "field description 字符串（最长 %(max_length)s 位）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: True\n",
      "-------------\n",
      "field user.UserProfile.info\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name info\n",
      "field type <class 'DjangoUeditor.models.UEditorField'>\n",
      "field description 文本\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: True\n",
      "-------------\n",
      "field user.UserProfile.created\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name created\n",
      "field type <class 'django.db.models.fields.DateTimeField'>\n",
      "field description 日期（带时间）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: True\n",
      "-------------\n",
      "field user.UserProfile.modified\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name modified\n",
      "field type <class 'django.db.models.fields.DateTimeField'>\n",
      "field description 日期（带时间）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: True null: True\n",
      "-------------\n",
      "field user.UserProfile.type\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name type\n",
      "field type <class 'django.db.models.fields.CharField'>\n",
      "field description 字符串（最长 %(max_length)s 位）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: False null: False\n",
      "-------------\n",
      "field user.UserProfile.groups\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name groups\n",
      "field type <class 'django.db.models.fields.related.ManyToManyField'>\n",
      "field description 多对多关系\n",
      "is_ralation True\n",
      "many_to_one False\n",
      "many_to_many True\n",
      "one_to_many False\n",
      "one_to_one False\n",
      "related_model <class 'django.contrib.auth.models.Group'>\n",
      "blank: True null: False\n",
      "-------------\n",
      "field user.UserProfile.user_permissions\n",
      "model <class 'user.models.UserProfile'>\n",
      "field name user_permissions\n",
      "field type <class 'django.db.models.fields.related.ManyToManyField'>\n",
      "field description 多对多关系\n",
      "is_ralation True\n",
      "many_to_one False\n",
      "many_to_many True\n",
      "one_to_many False\n",
      "one_to_one False\n",
      "related_model <class 'django.contrib.auth.models.Permission'>\n",
      "blank: True null: False\n",
      "-------------\n",
      "field <ManyToOneRel: invoice.sale>\n",
      "model <class 'user.models.Clerk'>\n",
      "field name clerk_sale\n",
      "field type <class 'django.db.models.fields.reverse_related.ManyToOneRel'>\n",
      "field <ManyToOneRel: invoice.sale>\n",
      "-------------\n",
      "field <ManyToOneRel: invoice.purchase>\n",
      "model <class 'user.models.Clerk'>\n",
      "field name purchase\n",
      "field type <class 'django.db.models.fields.reverse_related.ManyToOneRel'>\n",
      "field <ManyToOneRel: invoice.purchase>\n",
      "-------------\n",
      "field user.Clerk.userprofile_ptr\n",
      "model <class 'user.models.Clerk'>\n",
      "field name userprofile_ptr\n",
      "field type <class 'django.db.models.fields.related.OneToOneField'>\n",
      "field description 一对一关系\n",
      "is_ralation True\n",
      "many_to_one False\n",
      "many_to_many False\n",
      "one_to_many False\n",
      "one_to_one True\n",
      "related_model <class 'user.models.UserProfile'>\n",
      "blank: False null: False\n",
      "-------------\n",
      "field user.Clerk.identity\n",
      "model <class 'user.models.Clerk'>\n",
      "field name identity\n",
      "field type <class 'django.db.models.fields.CharField'>\n",
      "field description 字符串（最长 %(max_length)s 位）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: False null: False\n",
      "-------------\n",
      "field user.Clerk.base_pay\n",
      "model <class 'user.models.Clerk'>\n",
      "field name base_pay\n",
      "field type <class 'django.db.models.fields.IntegerField'>\n",
      "field description 整数\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: False null: False\n",
      "-------------\n",
      "field user.Clerk.commission\n",
      "model <class 'user.models.Clerk'>\n",
      "field name commission\n",
      "field type <class 'django.db.models.fields.CharField'>\n",
      "field description 字符串（最长 %(max_length)s 位）\n",
      "is_ralation False\n",
      "many_to_one None\n",
      "many_to_many None\n",
      "one_to_many None\n",
      "one_to_one None\n",
      "related_model None\n",
      "blank: False null: False\n",
      "-------------\n",
      "field user.Clerk.fk_store\n",
      "model <class 'user.models.Clerk'>\n",
      "field name fk_store\n",
      "field type <class 'django.db.models.fields.related.ForeignKey'>\n",
      "field description 外键(由相关字段确定)\n",
      "is_ralation True\n",
      "many_to_one True\n",
      "many_to_many False\n",
      "one_to_many False\n",
      "one_to_one False\n",
      "related_model <class 'organization.models.Store'>\n",
      "blank: False null: False\n",
      "-------------\n"
     ]
    }
   ],
   "source": [
    "from user.models import Clerk, UserProfile\n",
    "for field in Clerk._meta.get_fields(include_parents=True,include_hidden=False):\n",
    "    try:\n",
    "        '''\n",
    "        django/db/models/fields \n",
    "        '''\n",
    "        print('field',field)\n",
    "        print('model',field.model)\n",
    "        print('field name',field.name)\n",
    "        print('field type', type(field))\n",
    "        print('field description', field.description)\n",
    "        \n",
    "        print('is_ralation',field.is_relation)\n",
    "        print('many_to_one',field.many_to_one)\n",
    "        print('many_to_many',field.many_to_many)\n",
    "        print('one_to_many',field.one_to_many)\n",
    "        print('one_to_one',field.one_to_one)\n",
    "        print('related_model',field.related_model)\n",
    "        \n",
    "        print('blank:', field.blank, 'null:', field.null)  # field option\n",
    "        '''\n",
    "        /anaconda3/envs/django/lib/python3.6/site-packages/django/db/models/__init__.py\n",
    "        class Field(RegisterLookupMixin):\n",
    "            \"\"\"Base class for all field types\"\"\"\n",
    "            ......\n",
    "            many_to_many = None\n",
    "            many_to_one = None\n",
    "            one_to_many = None\n",
    "            one_to_one = None\n",
    "            related_model = None\n",
    "            ......\n",
    "        '''\n",
    "        '''\n",
    "        django.db.models.fields.related中\n",
    "        class ForeignKey(ForeignObject):\n",
    "            # Field flags\n",
    "            many_to_many = False\n",
    "            many_to_one = True\n",
    "            one_to_many = False\n",
    "            one_to_one = False\n",
    "        class OneToOneField(ForeignKey): \n",
    "            # Field flags\n",
    "            many_to_many = False\n",
    "            many_to_one = False\n",
    "            one_to_many = False\n",
    "            one_to_one = True\n",
    "        ManyToManyField(RelatedField):\n",
    "            # Field flags\n",
    "            many_to_many = True\n",
    "            many_to_one = False\n",
    "            one_to_many = False\n",
    "            one_to_one = False\n",
    "        '''\n",
    "    except:\n",
    "        print('field',field)\n",
    "    print('-------------')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from django.db.models.fields import DateTimeField, DateField\n",
    "from django.db.models.fields.related import ForeignKey\n",
    "print(type(Clerk._meta.get_field('date_joined')) is DateTimeField)\n",
    "print(type(Clerk._meta.get_field('fk_store')) is ForeignKey)\n",
    "from DjangoUeditor.models import UEditorField\n",
    "print(type(UserProfile._meta.get_field('info')) is UEditorField)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['AutoField', 'BLANK_CHOICE_DASH', 'BigAutoField', 'BigIntegerField', 'BinaryField', 'BooleanField', 'CharField', 'CommaSeparatedIntegerField', 'DateField', 'DateTimeField', 'DecimalField', 'DurationField', 'EmailField', 'Empty', 'Field', 'FieldDoesNotExist', 'FilePathField', 'FloatField', 'GenericIPAddressField', 'IPAddressField', 'IntegerField', 'NOT_PROVIDED', 'NullBooleanField', 'PositiveIntegerField', 'PositiveSmallIntegerField', 'SlugField', 'SmallIntegerField', 'TextField', 'TimeField', 'URLField', 'UUIDField']\n"
     ]
    }
   ],
   "source": [
    "from stdimage.models import StdImageField\n",
    "from DjangoUeditor.models import UEditorField\n",
    "\n",
    "from django.db.models.fields import DateTimeField, DateField, CharField, IntegerField, TextField, FilePathField\n",
    "from django.db.models.fields.related import ForeignKey  # this model many_to_one that model\n",
    "from django.db.models.fields.files import FileField, ImageField\n",
    "print(django.db.models.fields.__all__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "from datetime import datetime\n",
    "import pandas as pd\n",
    "from organization.models import Store\n",
    "test_clerk = Clerk()\n",
    "test_clerk.username = 'huyishi'\n",
    "test_clerk.set_password('123456')\n",
    "test_clerk.type = '01'\n",
    "test_clerk.identity='330681199403152453'\n",
    "test_clerk.base_pay=5000\n",
    "test_clerk.commission='00'\n",
    "test_clerk.fk_store = Store.objects.get(id=1)\n",
    "test_clerk.created = datetime(2019, 2, 20, 10, 10)\n",
    "test_clerk.save()\n",
    "\n",
    "record = {\n",
    "    'username':'huyishi',\n",
    "    'password':'123456',\n",
    "    'type':'01',\n",
    "    'identity':'330681199403152453',\n",
    "    'base_pay':5000,\n",
    "    'commission':'00',\n",
    "    'fk_store':Store.objects.get(id=1),\n",
    "    'created':datetime(2019, 2, 20, 10, 10),\n",
    "}\n",
    "new_clerk = Clerk(**record)\n",
    "new_clerk.save()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "from django.apps import apps\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
